package com.jh.base;

public enum RepStatusCode {

    UNKNOWN_ERROR(-1, "system is busy", "系统繁忙"),
    SUCCESS(200, "success", "请求成功"),
    BUSINESS_ERROR(5001, "business_error", "业务异常"),
    ILLEGAL_PARAMETER_ERROR(5002, "illegal_argument_error", "参数错误"),
    NO_AUTH_ERROR(403, "no_auth_error", "权限认证错误"),
    PARAMETERS_OF_THE_ABNORMAL(400,"Parameters of the abnormal","参数异常"),

    NO_LOGIN(530,"no_login","未登陆"),
    // 用于getSession前端区分
    NO_LOGIN5301(5301,"no_login","未登陆"),
    LOGIN_ERROR(4011 ,"login_error","登陆失败账户不存在"),
    ERROR_500(500,"500","500"),
    ERROR_404(404,"404","404");




    private int code;
    private String reason;
    private String description;

    RepStatusCode(int code, String reason, String description) {
        this.code = code;
        this.reason = reason;
        this.description = description;
    }

    public int getCode() {
        return code;
    }

    public RepStatusCode setCode(int code) {
        this.code = code;
        return this;
    }

    public String getReason() {
        return reason;
    }

    public RepStatusCode setReason(String reason) {
        this.reason = reason;
        return this;
    }

    public String getDescription() {
        return description;
    }

    public RepStatusCode setDescription(String description) {
        this.description = description;
        return this;
    }

    public static String toMarkdownTable() {
        StringBuilder stringBuilder = new StringBuilder("error_code | error_reason | error_description");
        stringBuilder.append("\n:-: | :-: | :-:\n");
        for (RepStatusCode error : RepStatusCode.values()) {
            stringBuilder.append(String.format("%s | %s | %s", error.getCode(), error.getReason(), error.getDescription())).append("\n");
        }
        return stringBuilder.toString();
    }

}
